Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • added industry standard dotenv parsing regex for adding envvars in settings

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Dec 12, 2025 3:21am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 12, 2025

Greptile Overview

Greptile Summary

Enhanced dotenv parsing to support industry-standard .env file formats including comment detection, quote handling, and export prefix removal. The developer addressed previous feedback by fixing the empty string regex pattern (changed /^=*$/ to /^=+$/) and increased the base64 detection threshold from 10 to 20 characters.

Key improvements:

  • Strips export prefix for shell-compatible env files
  • Handles inline comments ( #) for unquoted values
  • Removes surrounding quotes (", ', `)
  • Filters out malformed base64 strings that were incorrectly split

Remaining concern:

  • Base64 detection heuristic may reject edge case where a long environment variable name (>20 chars) without underscores has a value consisting only of equals signs (e.g., VERYLONGAPIKEYNAME123=====). This is unlikely in practice but technically valid.

Confidence Score: 4/5

  • Safe to merge with minimal risk - addresses previous feedback and adds robust dotenv parsing
  • The implementation correctly handles standard dotenv formats including comments, quotes, and export syntax. The developer responded to previous PR feedback by fixing the regex bug and adjusting thresholds. The remaining base64 detection edge case is extremely unlikely to occur in real-world usage (requires 20+ char variable name without underscores AND value of only equals signs). The changes are well-scoped to the parsing function with no side effects.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/environment/environment.tsx 4/5 Enhanced dotenv parsing with support for comments, quotes, and export syntax - base64 detection heuristic may reject rare edge cases

Sequence Diagram

sequenceDiagram
    participant User
    participant Component as EnvironmentVariables
    participant Parser as parseEnvVarLine
    participant API as Save/Upsert Mutations
    
    User->>Component: Paste env vars (Ctrl+V)
    Component->>Component: handlePaste(e, index)
    Component->>Component: Split by newline
    
    loop For each line
        Component->>Parser: parseEnvVarLine(line)
        Parser->>Parser: Trim whitespace
        
        alt Line is comment or empty
            Parser-->>Component: return null
        else Line contains export
            Parser->>Parser: Remove "export " prefix
        end
        
        Parser->>Parser: Find '=' index
        Parser->>Parser: Extract key before '='
        Parser->>Parser: Validate key with ENV_VAR_PATTERN
        
        alt Key invalid
            Parser-->>Component: return null
        end
        
        Parser->>Parser: Extract value after '='
        
        alt Looks like base64 + padding only + length > 20
            Parser-->>Component: return null (reject split base64)
        end
        
        alt Value not quoted
            Parser->>Parser: Remove inline comments (\s#)
        end
        
        Parser->>Parser: Strip quotes if present
        Parser-->>Component: return {key, value, id}
    end
    
    Component->>Component: Filter valid entries
    Component->>Component: Update envVars state
    
    User->>Component: Click Save
    Component->>API: savePersonalMutation.mutateAsync()
    Component->>API: upsertWorkspaceMutation.mutateAsync()
    API-->>Component: Success
    Component->>Component: Update initial refs
    Component-->>User: Changes saved
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit cb9b881 into staging Dec 12, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/envvarss branch December 12, 2025 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants